class_name PickUp
extends Area2D

@onready var animation_player: AnimationPlayer = $AnimationPlayer

var getmagnet := false
var target: CharacterBody2D

func _physics_process(_delta: float) -> void:
	if getmagnet:
		position += (target.position - position) / 5
		return
	position.y += 1

func _on_body_entered(body: CharacterBody2D) -> void:
	getmagnet = true
	target = body
	#print("进来了")

func _on_item_body_body_entered(body: CharacterBody2D) -> void:
	Game.on_item_picked_up(body, self)
	queue_free()

func _on_visible_on_screen_enabler_2d_screen_exited() -> void:
	queue_free()
